package com.spa.interfaces.admin;

import com.spa.application.command.admin.ShopAddCommand;
import com.spa.application.command.admin.ShopEditCommand;
import com.spa.application.command.admin.ShopEditIdCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.AllShopDTO;
import com.spa.application.dto.admin.ShopDTO;
import com.spa.application.dto.admin.ShopExportDTO;
import com.spa.application.dto.admin.ShopMaxRuleDTO;
import com.spa.application.query.BaseIdQuery;
import com.spa.application.query.admin.ShopQuery;
import com.spa.application.service.ShopApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("admin/shop")
public class ShopController extends BaseController {

    @Resource
    private ShopApplicationService shopApplicationService;

    @PostMapping("add")
    public ResponseMessage addShop(@Validated @RequestBody ShopAddCommand command) {
        shopApplicationService.addShop(command);
        return responseHelper.success();
    }

    @PostMapping("edit")
    public ResponseMessage editShop(@Validated @RequestBody ShopEditCommand command) {
        shopApplicationService.editShop(command);
        return responseHelper.success();
    }

    @PostMapping("/pageShop")
    public ResponseMessage<PageResult<ShopDTO>> pageShop(@RequestBody ShopQuery query) {
        return responseHelper.success(shopApplicationService.pageShop(query));
    }

    @PostMapping("/getAllShop")
    public ResponseMessage<PageResult<AllShopDTO>> getAllShop() {
        return responseHelper.success(shopApplicationService.getAllShop());
    }

    @PostMapping("export")
    public void exportShop(HttpServletResponse response, @RequestBody ShopQuery query) throws Exception {
        exportQueryResult(response, shopApplicationService.shopList(query), "门店列表", "门店列表", ShopExportDTO.class);
    }

    @PostMapping("/detail")
    public ResponseMessage<ShopDTO> detail(@RequestBody ShopQuery query) {
        return responseHelper.success(shopApplicationService.detail(query));
    }

    @PostMapping("/offline")
    public ResponseMessage offline(@Validated @RequestBody ShopEditIdCommand command) {
        shopApplicationService.offLine(Long.parseLong(command.getId()));
        return responseHelper.success();
    }

    @PostMapping("/online")
    public ResponseMessage online(@Validated @RequestBody ShopEditIdCommand command) {
        shopApplicationService.onLine(Long.parseLong(command.getId()));
        return responseHelper.success();
    }

    @PostMapping("/massagistRuleMaxVal")
    public ResponseMessage<ShopMaxRuleDTO> massagistRuleMaxVal(@Validated @RequestBody BaseIdQuery baseIdQuery) {
        return responseHelper.success(shopApplicationService.massagistRuleMaxVal(baseIdQuery.getId()));
    }

    @PostMapping("/ruleList")
    public ResponseMessage<ShopMaxRuleDTO> ruleList(@Validated @RequestBody BaseIdQuery baseIdQuery) {
        return responseHelper.success(shopApplicationService.queryShopRuleList(baseIdQuery.getId()));
    }

}
